package windows;

import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Vector;

import main.ImageLibrary;
import main.VirtualRoom;

import base.Button;
import base.Window;

public class CarRemote extends Window {
	
	private int lockState = -1;
	private int startState = -1;
	

	private Vector<Button> buttons = new Vector<Button>( );
	
	//change for your screen
	public CarRemote( ){
		super( "Car Remote" , "Garage[0]", "Favorites");
		buttons.add( new Button( "Lock" , new Point( Window.width / 2 -72, 245 ) , "Images/lock.png", false, true ) );
		//buttons.add( new Button( "Unlock" , new Point( 100 , 12 ) , "Images/unlock.png", false, true ) );
		//buttons.add( new Button( "Alarm" , new Point( 25 , 75 ) , "Images/alarm.png", false, true ) );
		buttons.add( new Button( "Start" , new Point( Window.width / 2, 245 ) , "Images/start.png", false, true ) );
		buttons.add( new Button( "Car" , new Point( 20,20 ) , "Images/car.png", false, false ) );
		ImageLibrary.add( "carStart" , "Images/start.png" );
		ImageLibrary.add( "carLock" , "Images/lock.png" );
		ImageLibrary.add( "carUnlock" , "Images/unlock.png" );
		ImageLibrary.add( "carAlarm" , "Images/alarm.png" );
		ImageLibrary.add( "car" , "Images/car.png" );

	}
	
	public void draw(Graphics2D g2d) {
		for( Button but : buttons )
			but.draw( g2d );
		
		//draw car image
		int centerCarX = VirtualRoom.width/2 - ImageLibrary.get( "car" ).getWidth( )/2;
		int centerCarY = VirtualRoom.height/2 - ImageLibrary.get( "car" ).getHeight( )/2;
		VirtualRoom.graphics.drawImage( ImageLibrary.get( "car" ) , centerCarX , centerCarY , VirtualRoom.getInstance( ) );
		
		//lock/unlock
		int centerLockX = VirtualRoom.width/2 - ImageLibrary.get( "carLock" ).getWidth( )/2 -80;
		int centerLockY = VirtualRoom.height/2 - ImageLibrary.get( "carLock" ).getHeight( )/2;
		if(lockState == -1){
			VirtualRoom.graphics.drawImage( ImageLibrary.get( "carUnlock" ) , centerLockX , centerLockY , VirtualRoom.getInstance( ) );
		}
		else{
			VirtualRoom.graphics.drawImage( ImageLibrary.get( "carLock" ) , centerLockX , centerLockY , VirtualRoom.getInstance( ) );
		}
		
		//start/alarm
		int centerStartX = VirtualRoom.width/2 - ImageLibrary.get( "carStart" ).getWidth( )/2 +80;
		int centerStartY = VirtualRoom.height/2 - ImageLibrary.get( "carStart" ).getHeight( )/2;
		if(startState == -1){
			VirtualRoom.graphics.drawImage( ImageLibrary.get( "carAlarm" ) , centerStartX , centerStartY , VirtualRoom.getInstance( ) );
		}
		else{
			VirtualRoom.graphics.drawImage( ImageLibrary.get( "carStart" ) , centerStartX , centerStartY , VirtualRoom.getInstance( ) );
		}
		
		
	}

	public void fingerPressed(Point location) {
		for( Button but : buttons ){
			if( but.press( location.x , location.y ) ){
				if( but.getName( ).equals( "Lock" ) ) {
					
					if(lockState == -1){
						but.setImage("Images/unlock.png");
					}
					else{
						but.setImage("Images/lock.png");
					}
					lockState *= -1;
				}
				
				if( but.getName( ).equals( "Start" ) ) {
					if(startState == -1){
						but.setImage("Images/alarm.png");
					}
					else{
						but.setImage("Images/start.png");
					}
					startState *= -1;
				}
				return;
			}
		}
	}

	public void fingerReleased(Point location) {
		for( Button but : buttons ){			
			but.release( );
		}
	}

	public void gestureHorizontal(int amount) {	
	}

	public void gestureVertical(int amount) {	
	}

}